package com.fantastic.web.controller.app;

import com.fantastic.common.exception.enums.RespStatusInfo;
import com.fantastic.common.result.ResultData;
import com.fantastic.common.utils.CheckUtil;
import com.fantastic.common.utils.RandomUtil;
import com.fantastic.mapper.zjs.AccountMapper;
import com.fantastic.model.pojo.zjs.Account;
import com.fantastic.model.pojo.zjs.User;
import com.fantastic.service.zjs.AccountService;
import com.fantastic.service.zjs.AuthService;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author: rxx
 * @since: 2024/6/13 15:38
 * @description: 邮箱验证
 */
@RestController
@RequestMapping("/verify")
public class VerificationController {
    @Resource
    private Cache<Object, Object> cache;

    @Resource(name = "appAuth")
    private AuthService authService;

    /**
     * 发送验证码
     *
     * @param phone 手机号
     * @return
     */
    @GetMapping("/sendCode")
    public String sendCode(String phone) {
        //进行登录验证，手机号存在返回用户信息
        Account account = new Account();
        account.setPhone(phone);
        authService.login(account);
        String code = RandomUtil.getCodeNumber(6);
        //发送验证码
        //将验证码添加或是更新到缓存中
        cache.put(RandomUtil.codeKey, code);
        System.out.println(code);
        return code;
    }

}
